package com.java.test.agent.module.info;

import com.java.test.agent.module.info.dto.AgentCensusDTO;
import com.java.test.agent.module.info.dto.AgentInfoDTO;
import com.java.test.agent.module.info.dto.AgentInfoQueryDTO;
import com.java.test.agent.module.info.dto.AgentInfoUpdateDTO;
import com.java.test.agent.module.info.vo.AgentCensusVO;
import com.java.test.agent.module.info.vo.AgentInfoVO;
import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 代理Controller
 *
 * @author lijie1
 * @date 2020/6/30 0030
 */
@Slf4j
@RestController
@RequestMapping("/agent/agentInfo")
public class AgentInfoController extends BaseController {

    private AgentInfoService agentInfoService;
    @Autowired
    public void setAgentInfoService(AgentInfoService agentInfoService) {
        this.agentInfoService = agentInfoService;
    }


    /**
     * 查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<AgentInfoVO>> selectByList(@RequestBody @Valid AgentInfoQueryDTO queryDTO) {
        log.debug("----------代理列表查询----------");
        return agentInfoService.getSelectByList(queryDTO);
    }

    /**
     * 解冻
     * @return
     */
    @RequestMapping(value = "/pass",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<AgentInfoVO>> passByIds(@RequestBody @Valid AgentInfoDTO DTO, HttpServletRequest request) {
        log.debug("----------代理解冻----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "代理管理-代理列表-代理解冻");
        return agentInfoService.passByIds(DTO);
    }

    /**
     * 冻结
     * @return
     */
    @RequestMapping(value = "/fail",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<AgentInfoVO>> failByIds(@RequestBody @Valid AgentInfoDTO DTO, HttpServletRequest request) {
        log.debug("----------代理冻结----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "代理管理-代理列表-代理冻结");
        return agentInfoService.failByIds(DTO);
    }

    /**
     * 查询费率
     * @return
     */
    @RequestMapping(value = "/selectScale",method = RequestMethod.POST)
    public ResponseDTO<AgentInfoVO> selectScale(@RequestBody @Valid AgentInfoDTO DTO) {
        log.debug("----------查询费率----------");
        return agentInfoService.selectScaleByIds(DTO);
    }

    /**
     * 统计代理商信息
     * @return
     */
    @RequestMapping(value = "/getAgentCensus",method = RequestMethod.POST)
    public ResponseDTO<AgentCensusVO> getAgentCensus(@RequestBody @Valid AgentCensusDTO DTO) {
        log.debug("----------统计代理商信息----------");
        return agentInfoService.getAgentCensus(DTO);
    }

    /**
     * 修改费率
     * @return
     */
    @RequestMapping(value = "/updateScale",method = RequestMethod.POST)
    public ResponseDTO<AgentInfoVO> updateScale(@RequestBody @Valid AgentInfoUpdateDTO DTO, HttpServletRequest request) {
        log.debug("----------修改费率----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "代理管理-代理列表-修改费率");
        return agentInfoService.updateScale(DTO);
    }
}
